﻿using System.Net.Sockets;

namespace BlazorAdmin.Tcp.Server
{
    /// <summary>
    /// Socket套接字连接池
    /// </summary>
    internal class SocketPool
    {
        private Stack<SocketAsyncEventArgs> pool;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="capacity">初始化栈大小</param>
        public SocketPool(int capacity)
        {
            pool = new Stack<SocketAsyncEventArgs>(capacity);
        }

        /// <summary>
        /// 压入接收堆栈
        /// </summary>
        /// <param name="item">实体</param>
        public void Push(SocketAsyncEventArgs item) => pool.Push(item);

        /// <summary>
        /// 移除并返回接收栈顶对象
        /// </summary>
        /// <returns></returns>
        public SocketAsyncEventArgs Pop() => pool.Pop();

        /// <summary>
        /// 获取连接缓存对象的数量
        /// </summary>
        public int Count => pool.Count;
    }
}
